import json

from ronglian_sms_sdk import SmsSDK

accId = '8aaf0708780055cd0178d3060c314ef0'
accToken = 'a697cb643f744b62a12e38e77e054d97'
appId = '8aaf0708780055cd0178d3060d234ef7'


class Sms_Util:
    def __new__(cls, *args, **kwargs):
        if not hasattr(Sms_Util, "_instance"):
            cls._instance = super().__new__(cls, *args, **kwargs)
            # 创建一个smssdk对象，这里只执行一次，使用smssdk对象只有一个。
            cls._instance.sms_sdk = SmsSDK(accId, accToken, appId)

        return cls._instance

    def send_message(self,tid,mobile,datas):
        # sdk = SmsSDK(accId, accToken, appId)
        # tid = '1'
        # mobile = '19852744199'
        # datas = ('123546', '1')

        resp = self.sms_sdk.sendMessage(tid, mobile, datas)
        resp_dict = json.loads(resp)
        if resp_dict.get("statusCode") == "000000":
            print("发送短信成功")
            return 0
        else:
            print("发送短信失败")
            return 1


if __name__ == '__main__':
    Sms_Util().send_message()
